package net.dgg.robot.task.quartz;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时器
 *
 * @author tanghom
 */
@Component
public class TestTimer {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * 企业微信机器人推送地址
     */
    @Value("${webhookUrl}")
    private String webhookUrl;
    /**
     * 用户数据文件路径
     */
    @Value("${userFilePath}")
    private String userFilePath;
    @Value("${time.content.startWork}")
    private String startWorkContent;
    @Value("${time.content.endWork}")
    private String endWorkContent;
    @Value("${time.content.dinnerMealRemind}")
    private String dinnerMealRemindContent;
    @Value("${time.content.lunchMealRemind}")
    private String lunchMealRemindContent;
    /**
     * 每天早上8点20定时器
     */
    @Scheduled(cron = "${scheduled.startWork}")
    public void startWork() {
        logger.info("上班打卡提醒");
        try {
            new HttpUtil().pushWorkWx(webhookUrl,startWorkContent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 每天晚上8点30和50提醒
     */
    @Scheduled(cron = "${scheduled.endWork}")
    public void endWork() {
        logger.info("下班打卡提醒");
        try {
            new HttpUtil().pushWorkWx(webhookUrl,endWorkContent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 午餐订餐提醒
     */

    @Scheduled(cron = "${scheduled.lunchMealRemind}")
    public void mealRemind() {
        logger.info("订餐提醒！");
        try {
            new HttpUtil().pushWorkWx(webhookUrl,lunchMealRemindContent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 晚餐订餐提醒
     */

    @Scheduled(cron = "${scheduled.dinnerMealRemind}")
    public void dinnerMealRemind() {
        logger.info("订餐提醒！");
        try {
            new HttpUtil().pushWorkWx(webhookUrl,dinnerMealRemindContent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * test
     */
    @Scheduled(cron = "${scheduled.test}")
    public void test() {
        if (!"".equals(userFilePath) && !"".equals(webhookUrl)&&1==HttpUtil.isWorkDay()) {
            logger.info("运行情况111111111"+userFilePath+">>>>>>>>>>"+webhookUrl);
        }
//        logger.info("运行情况"+userFilePath+">>>>>>>>>>"+webhookUrl);
//        List notList = new HttpUtil().queryNoClockInUserList(userFilePath);
//        String notStr = JsonUtil.obj2Json(notList);
//        logger.info(notStr);
    }

}
